<template>
  <section>
    <el-button
      v-permission="installPermissions.permissions.plan.edit"
      @click="handleEdit(row)"
      type="text"
      size="small"
    >
      编辑
    </el-button>
    <el-button
      @click="handleMateriel(row)"
      type="text"
      size="small"
    >
      设置农资
    </el-button>
    <el-button
      v-permission="installPermissions.permissions.plan.del"
      @click="handleDelete(row)"
      type="text"
      size="small"
    >
      删除
    </el-button>
  </section>
</template>
<style>
</style>
<script>
export default {
  props: {
    row: {
      type: Object,
      default: function() {
        return {};
      }
    },
    col: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  methods: {
    handleStatus() {
      let ops = this.row.status.value == "EFFECTIVED" ? "禁用" : "激活";
      let status =
        this.row.status.value == "EFFECTIVED" ? "INVALID" : "EFFECTIVED";
      this.$confirm("此操作将" + ops + "该用户, 是否继续?", ops + "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$api.user.status(this.row.id, status, () => {
          this.$message({
            type: "success",
            message: ops + "用户成功",
            onClose: this.$emit("deleteDone", this.row)
          });
        });
      });
    },
    handleDelete() {
      this.$confirm("此操作将删除该方案, 是否继续?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$api.plan.delete(this.row.id, () => {
          this.$message({
            type: "success",
            message: "删除方案成功",
            onClose: () => {
              this.$emit("deleteDone", this.row);
            }
          });
        });
      });
    },

    handleEdit() {
      this.$emit("editRow", this.row);
    },
    handleMateriel() {
      this.$emit("setMateriel", this.row);
    }
  }
};
</script>
